package cn.sdormitory.controller.canteen;

import cn.sdormitory.canteen.service.FoodSampleService;
import cn.sdormitory.canteen.vo.FoodHealthCartVO;
import cn.sdormitory.canteen.vo.FoodSampleVO;
import cn.sdormitory.common.api.CommonResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(tags = "food-Health-Cart=> 食品采样")
@RequestMapping("/food/sample")
public class FoodSampleController {
    @Autowired
    private FoodSampleService foodSampleService;

    @ApiOperation("getSamplePageList => 分页查询健康证")
    @PostMapping(value = "/getSamplePageList")
    public CommonResult<IPage<FoodSampleVO>> getSamplePageList(@RequestBody Map<String,Object> map){
        IPage<FoodSampleVO> pageList =  foodSampleService.getPage(map);
        return CommonResult.success(pageList);
    }

    @ApiOperation("addOrUpdateHealthCartInfo => 新增or修改健康证信息")
    @PostMapping(value = "/addOrUpdateSampleInfo")
    public CommonResult<Integer> addOrUpdateSampleInfo(@RequestBody FoodSampleVO vo){
        int num =  foodSampleService.saveOrUpdateFoodSample(vo);
        if(num==0){
            CommonResult.failed();
        }
        return CommonResult.success();
    }

    @ApiOperation("deleteHealthCartById => 根据ID删除采样记录")
    @PostMapping(value = "/deleteSampleById")
    public CommonResult<Integer> deleteSampleById(@RequestBody FoodHealthCartVO vo){
        int num =  foodSampleService.deleteFoodSampleById(vo.getId());
        if(num==0){
            CommonResult.failed();
        }
        return CommonResult.success();
    }
}
